package @@packageName@@;

import com.google.gwt.json.client.*;

public class PrimitiveJsonizer {
    public static char toJavaChar(JSONValue arg0) {
        JSONString string = arg0.isString();
        if (string == null) {
            throw new JSONException("expected JSONString");
        }

        return string.stringValue().charAt(0);
    }

    public static boolean toJavaBoolean(JSONValue arg0) {
        JSONBoolean jsonBoolean = arg0.isBoolean();
        if (jsonBoolean == null) {
            throw new JSONException("expected JSONBoolean");
        } else {
            return jsonBoolean.booleanValue();
        }
    }

    public static short toJavaShort(JSONValue arg0) {
        JSONString str = arg0.isString();
        if (str == null) {
            throw new JSONException("expected JSONString");
        }
        String n = str.stringValue();

        try {
            return Short.parseShort(n);    
        } catch (NumberFormatException nfe) {
            throw new JSONException("could not parse short value [" + n + "]", nfe);
        }
    }

    public static int toJavaInteger(JSONValue arg0) {
        JSONString str = arg0.isString();
        if (str == null) {
            throw new JSONException("expected JSONString");
        }
        String n = str.stringValue();

        try {
            return Integer.parseInt(n);    
        } catch (NumberFormatException nfe) {
            throw new JSONException("could not parse integer value [" + n + "]", nfe);
        }
    }

    public static long toJavaLong(JSONValue arg0) {
        JSONString str = arg0.isString();
        if (str == null) {
            throw new JSONException("expected JSONString");
        }
        String n = str.stringValue();

        try {
            return Long.parseLong(n);    
        } catch (NumberFormatException nfe) {
            throw new JSONException("could not parse long value [" + n + "]", nfe);
        }
    }

    public static float toJavaFloat(JSONValue arg0) {
        JSONString str = arg0.isString();
        if (str == null) {
            throw new JSONException("expected JSONString");
        }
        String n = str.stringValue();

        try {
            return Float.parseFloat(n);    
        } catch (NumberFormatException nfe) {
            throw new JSONException("could not parse float value [" + n + "]", nfe);
        }
    }

    public static double toJavaDouble(JSONValue arg0) {
        JSONString str = arg0.isString();
        if (str == null) {
            throw new JSONException("expected JSONString");
        }
        String n = str.stringValue();

        try {
            return Float.parseFloat(n);    
        } catch (NumberFormatException nfe) {
            throw new JSONException("could not parse double value [" + n + "]", nfe);
        }
    }

    public static JSONValue toJsonChar(char arg0) {
        return new JSONString(Character.toString(arg0));
    }

    public static JSONValue toJsonBoolean(boolean arg0) {
        return JSONBoolean.getInstance(arg0);
    }

    public static JSONValue toJsonShort(short arg0) {
        return new JSONString(Short.toString(arg0));
    }

    public static JSONValue toJsonInteger(int arg0) {
        return new JSONString(Integer.toString(arg0));
    }

    public static JSONValue toJsonLong(long arg0) {
        return new JSONString(Long.toString(arg0));
    }

    public static JSONValue toJsonFloat(float arg0) {
        return new JSONString(Float.toString(arg0));
    }

    public static JSONValue toJsonDouble(double arg0) {
        return new JSONString(Double.toString(arg0));
    }
}
